import request from '@/utils/request'

//根据新闻id获取评论
export function getCommentByNewsId(newsId) {
    return fetch(`http://localhost:8082/comment?foreignId=${newsId}`).then(res => {
        if (res.status === 500) {
            this.$notify.error('系统错误')
            return {}
        }
        return res.json()
    }).then(res => {
        return {
            rate: res.rate,
            comments: res.comments
        }
    })
}

//评论内容
export function addComment(comment) {
    return fetch('http://localhost:8082/comment', {
        method: 'post',
        headers: {
            'Content-Type': 'application/json;charset=utf-8'
        },
        body: JSON.stringify(comment)
    }).then(res => {
        if (res.status === 200) {
            return true
        } else {
            return false
        }
    })
}

//评论成功新闻评论+1
export function addCommentNum(news) {
    return request({
        url: '/news',
        method: 'post',
        date: news,
    })
}
// 根据新闻id获取新闻
export function getNewsById(id) {
    return request.get('/news/' + id);
}
